/*
 * BuiltinFunctionObject.java - ScriptME
 * 
 * Copyright (c) 2009 Cesar Henriques <cesar at alttab.com.ar>.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Based on FESI Project
 * 
 * Contributors:
 * 	Jean-Marc Lugrin - initial API and implementation
 * 	Cesar Henriques <cesar at alttab.com.ar> - J2ME Porting and Extensions
 */
package org.scriptme.ecmascript.data;

import org.scriptme.ecmascript.exceptions.EcmaScriptException;
import org.scriptme.ecmascript.interpreter.Evaluator;

// TODO: Auto-generated Javadoc
/**
 * Implement the common functionality of all built-in functions.
 */
public abstract class BuiltinFunctionObject extends FunctionPrototype {

	/**
	 * Instantiates a new builtin function object.
	 * 
	 * @param functionPrototype
	 *            the function prototype
	 * @param evaluator
	 *            the evaluator
	 * @param functionName
	 *            the function name
	 * @param length
	 *            the length
	 */
	protected BuiltinFunctionObject(ESObject functionPrototype,
			Evaluator evaluator, String functionName, int length) {
		super(functionPrototype, evaluator, functionName, length);
	}

	// overrides
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.data.FunctionPrototype#putProperty(java.lang.String,
	 *      org.scriptme.ecmascript.data.ESValue, int)
	 */
	public void putProperty(String propertyName, ESValue propertyValue, int hash)
			throws EcmaScriptException {
		if (!propertyName.equals("prototype")) {
			super.putProperty(propertyName, propertyValue, hash);
		} // Allowed via putHiddenProperty, used internally !
	}

	/**
	 * get the string defining the function.
	 * 
	 * @return a string indicating that the function is native
	 */
	public String getFunctionImplementationString() {
		return "{[native: " + this.getClass().getName() + "]}";
	}

	/**
	 * Get the function parameter description as a string.
	 * 
	 * @return the function parameter string as (a,b,c)
	 */
	public String getFunctionParametersString() {
		return "(<" + getLengthProperty() + " args>)";
	}

	// overrides
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.scriptme.ecmascript.data.FunctionPrototype#toString()
	 */
	public String toString() {
		return "<" + this.getFunctionName() + ":" + this.getClass().getName()
				+ ">";
	}
}
